﻿/******************************************************************************

    Copyright (c) 2010, Sergey Mudrov
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are met:
        * Redistributions of source code must retain the above copyright
          notice, this list of conditions and the following disclaimer.
        * Redistributions in binary form must reproduce the above copyright
          notice, this list of conditions and the following disclaimer in the
          documentation and/or other materials provided with the distribution.
        * Neither the name of Sergey Mudrov nor the
          names of its contributors may be used to endorse or promote products
          derived from this software without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    DISCLAIMED. IN NO EVENT SHALL SERGEY MUDROV BE LIABLE FOR ANY
    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*******************************************************************************/

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using JeffWilcox.Utilities.Silverlight;
using System.Windows.Browser;
using System.Threading;
using System.IO;
using System.Text;
using System.Runtime.Serialization.Json;
using System.Reflection;
using VkApi.DataTypes;

namespace VkApi
{
    public partial class VkApi
    {
        /// <summary>
        /// Determines whether user installed this application.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <returns></returns>
        public long IsAppUser(ApiCallback<string> callback)
        {
            return this.IsAppUser(0, callback);
        }

        /// <summary>
        /// Determines whether its an application user for the specified callback and user ID.
        /// </summary>
        /// <param name="uid">The user ID.</param>
        /// <param name="callback">The callback.</param>
        /// <returns></returns>
        public long IsAppUser(long uid, ApiCallback<string> callback)
        {
            return this.SendRequest("isAppUser", callback,
                new Parameter[] { new Parameter("uid", uid.ToString()) });
        }

        /// <summary>
        /// Gets the user balance for this application.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <returns></returns>
        public long GetUserBalance(ApiCallback<int?> callback)
        {
            return this.SendRequest("getUserBalance", callback, null);
        }

        /// <summary>
        /// Gets the user settings in this application.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <returns></returns>
        public long GetUserSettings(ApiCallback<UserSettings> callback)
        {
            return this.SendRequest("getUserSettings", callback, null);
        }

        /// <summary>
        /// Gets the users group IDs.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <returns></returns>
        public long GetGroups(ApiCallback<long[]> callback)
        {
            return this.SendRequest("getGroups", callback, null);
        }

        /// <summary>
        /// Gets the groups base information.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <returns></returns>
        public long GetGroupsFull(ApiCallback<GroupInfo[]> callback)
        {
            return this.SendRequest("getGroupsFull", callback, null);
        }

        /// <summary>
        /// Gets the profiles.
        /// </summary>
        /// <param name="uids">The users IDs.</param>
        /// <param name="profileFields">The profile fields.</param>
        /// <param name="callback">The callback.</param>
        /// <returns></returns>
        public long GetProfiles(long[] uids, ProfileFields profileFields, ApiCallback<Profile[]> callback)
        {
            string uidsString = "";
            foreach (int i in uids)
                uidsString += i.ToString() + ",";
            uidsString = uidsString.Remove(uidsString.Length - 1);
            string profileFieldsString = profileFields.ToString().Replace(" ", "");

            return this.SendRequest("getProfiles", callback,
                new Parameter[] { new Parameter("uids", uidsString),new Parameter("fields", profileFieldsString) });
        }
    }
}
